
global dir "/Usersgsms data"

cd "$dir"

clear
set mem 100m
clear mata
clear matrix
set maxvar 8000
set more off


****************************** Results, Unweighted, With Baseline Vote Propensity (in in-text table and figure)
use gsms_diff_diff_16_finished.dta, clear


gen agt=1 if ag1_new==1 |ag2_new ==1
recode agt . =0 if ag3_new==1
gen ag1 = agt

gen interaction=ag1*ai_par_t_new
 
gen voted_2002=voted_11_05_2002
gen voted_2004=voted_11_02_2004
gen voted_2006=voted_11_07_2006
gen voted_2008=voted_11_04_2008
gen voted_2010=voted_11_02_2010
gen voted_2012=voted_11_06_2012
gen voted_2014=voted_11_04_2014

gen voted_first = voted_2002 if ag3_new ==1 
replace voted_first = voted_2006 if ag1_new ==1

replace t1_new =1 if t1_new ==2
replace t2_new =1 if t2_new ==2
replace ai_par_t_new =1 if ai_par_t_new ==2
recode interaction 2=1

*** Counter ==2 is for first parent, counter ==3 is second parent
sort gsmsid parentid
by gsmsid: gen counter=_n if parentid ~=""
 
save temp, replace
 

keep if parent ==0


reshape long voted_, i(gsmsid) j(year1)


tab year1, gen(yr)


encode gsmsid, gen(gsms)

tsset gsms year

gen after =1 if (year >1996 & year <.) 
recode after . =0 if year ~=. 

gen ai_par_tt=ai_par_t
recode ai_par_tt 2=1


gen ag1ai=ag1_new*ai_par_tt
gen ag2ai=ag2_new*ai_par_tt


save temp_resid, replace




gen int1=yr1*ag1*ai_par_tt
gen int2=yr2*ag1*ai_par_tt
gen int3=yr3*ag1*ai_par_tt
gen int4=yr4*ag1*ai_par_tt
gen int5=yr5*ag1*ai_par_tt
gen int6=yr6*ag1*ai_par_tt
gen int7=yr7*ag1*ai_par_tt



preserve
*** Simple Diff in Diff for Kids (Combined Cohort) by Race by Cohort by Year ***
************ Figure 3a *************************
xi:reg voted_  int2-int7  ai_par_tt ag1 i.ag1*i.year i.year i.ai_par_tt*i.year  age_days_1_1_1992 parent_base_prop_vote if avghhincome_new<=5.33 ,  cl(gsms) r
parmest, label list(parm label estimate min* max* p) level(95) saving(results, replace)
use results, clear
keep if _n<7
set obs 7
replace parm ="int1" in 7
destring parm, gen(parm2) ignore("int")
drop parm
rename parm2 parm
sort parm
replace estimate =0 if parm ==1
label variable estimate "Regression Coefficient"
label variable min95 "Lower 95% CI"
label variable max95 "Upper 95% CI"

#d;
twoway (line estimate parm, mcolor(black) msymbol(square) msize(small)) (rcap min95 max95 parm, lcolor(black)), 
yline(0, lp(dash) lcolor(red))
       graphregion(color(white)) 
       plotregion(color(white))
       aspect(.35)
       ysize(3.5)
	   yscale(range(-0.3(0.1)0.3))
	   ylabel(-0.3(0.1)0.3, nogrid)
       xlabel(1 "2002" 2 "2004" 3 "2006" 4 "2008" 5 "2010" 6 "2012" 7 "2014", labsize(small)  glcolor(gs13) nogmin)
       xtitle("{fontface Times New Roman:Years}" ,size(medium))
       ytitle("{fontface Times New Roman:Voted in Election}", size(medium)) 
	   ;
graph save kidsvoting_event.gph, replace;
#d cr
restore

       

preserve
*** Simple Diff in Diff for Kids (Combined Cohort) by Race by Cohort by Year ***
************ Figure 3b *************************
xi:reg voted_  int2-int7  ai_par_tt ag1 i.ag1*i.year i.year i.ai_par_tt*i.year  age_days_1_1_1992 parent_base_prop_vote if avghhincome_new>5.33 & avghhincome_new<.,  cl(gsms) r
parmest, label list(parm label estimate min* max* p) level(95) saving(results, replace)
use results, clear
keep if _n<7
set obs 7
replace parm ="int1" in 7
destring parm, gen(parm2) ignore("int")
drop parm
rename parm2 parm
sort parm
replace estimate =0 if parm ==1
label variable estimate "Regression Coefficient"
label variable min95 "Lower 95% CI"
label variable max95 "Upper 95% CI"

#d;
twoway (line estimate parm, mcolor(black) msymbol(square) msize(small)) (rcap min95 max95 parm, lcolor(black)), 
yline(0, lp(dash) lcolor(red))
       graphregion(color(white)) 
       plotregion(color(white))
       aspect(.35)
       ysize(3.5)
	   yscale(range(-0.3(0.1)0.3))
	   ylabel(-0.3(0.1)0.3, nogrid)
       xlabel(1 "2002" 2 "2004" 3 "2006" 4 "2008" 5 "2010" 6 "2012" 7 "2014", labsize(small)  glcolor(gs13) nogmin)
       xtitle("{fontface Times New Roman:Years}" ,size(medium))
       ytitle("{fontface Times New Roman:Voted in Election}", size(medium)) 
	   ;
#d cr
restore


